home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / RTVBE210.ZIP / PMODE.H < prev    next >
C/C++ Source or Header  |  1996-04-23  |  14KB  |  398 lines

  1. /****************************************************************************
  2. *
  3. *                               PM/Lite Library
  4. *
  5. *                    Copyright (C) 1996 SciTech Software.
  6. *                            All rights reserved.
  7. *
  8. * Filename:        $Workfile:   pmode.h  $
  9. * Version:        $Revision:   1.1  $
  10. *
  11. * Language:        ANSI C
  12. * Environment:    Real mode and 16/32 bit Protected Mode under MSDOS
  13. *
  14. * Description:    Header file for the DOS extender independant protected
  15. *                mode programming library. This library will need to be
  16. *                included in all programs that use SciTech Software's
  17. *                products that are to be compiled in protected mode.
  18. *
  19. *                This library provides pre-built selectors for the BIOS
  20. *                data area and VGA frame buffer, and methods for allocating
  21. *                your own selectors for physical memory. It also returns
  22. *                appropriate selectors for accessing memory allocated in
  23. *                the low DOS 1Mb memory area, and routines for accessing
  24. *                memory through a selector and offset. By using selectors
  25. *                for accessing memory outside of the applications linear
  26. *                address space, your code will be fully DPMI compliant and
  27. *                will run under Windows 3.1 and OS/2 2.x DOS boxes.
  28. *
  29. *                Works with the following:
  30. *
  31. *                    Real Mode DOS (large memory model)
  32. *
  33. *               16 bit Extenders:
  34. *
  35. *                    Windows 3.1
  36. *                    Borland DPMI16
  37. *
  38. *               32 bit Extenders:
  39. *
  40. *                    Windows 3.1 (Win32s)
  41. *                    Windows '95 (Win32)
  42. *                    Phar Lap TNT DOS Extender
  43. *                    Symantec DOSX
  44. *                    FlashTek X-32/X-32VM
  45. *                    Borland DPMI32
  46. *                    Rational DOS/4GW
  47. *                   DJGPP go32 for GNU C++          * NO SELECTORS YET!! *
  48. *
  49. *                Currently supports the following compilers:
  50. *
  51. *                    Borland C++ 3.1
  52. *                    Borland C++ 4.0, 16 bit
  53. *                    Borland C++ 4.0, 32 bit
  54. *                   Microsoft Visual C++ 1.5, 16 bit
  55. *                   Microsoft Visual C++ 1.5, 32 bit
  56. *                    Symantec C++ 6.1, 16 bit
  57. *                    Symantec C++ 6.1, 32 bit
  58. *                    Watcom C++ 10.0, 16 bit
  59. *                   Watcom C++ 10.0, 32 bit
  60. *                    Metaware High C++ 3.21, 32 bit
  61. *                    DJGPP port of GNU C++, 32 bit    * NO SELECTORS YET!! *
  62. *
  63. * $Date:   10 Apr 1996 18:15:40  $ $Author:   KendallB  $
  64. *
  65. ****************************************************************************/
  66.  
  67. #ifndef    __PMODE_H
  68. #define    __PMODE_H
  69.  
  70. #ifndef    __DEBUG_H
  71. #include "debug.h"
  72. #endif
  73.  
  74. /*--------------------------- Macros and Typedefs -------------------------*/
  75.  
  76. /* You will need to define one of the following before you compile this
  77.  * library for it to work correctly with the DOS extender that you are
  78.  * using when compiling for extended DOS:
  79.  *
  80.  *      DPMI16      - Borland's DPMI16 DOS Power Pack Extender
  81.  *        TNT            - Phar Lap TNT DOS Extender
  82.  *        DOSX        - Symantec C++ DOSX
  83.  *        X32VM        - Flashtek X-32/X-32VM
  84.  *      DPMI32      - Borland's DPMI32 DOS Power Pack Extender
  85.  *        DOS4GW        - Rational DOS/4GW and DOS/4GW Professional
  86.  *        DJGPP        - DJGPP port of GNU C++
  87.  *
  88.  * If none is specified, we will automatically determine which operating
  89.  * system is being targetted and the following will be defined (provided by
  90.  * debug.h header file):
  91.  *
  92.  *        __MSDOS16__        - Default for 16 bit MSDOS mode
  93.  *        __MSDOS32__        - Default for 32 bit MSDOS
  94.  *        __WINDOWS16__    - Default for 16 bit Windows
  95.  *        __WINDOWS32__    - Default for 32 bit Windows
  96.  *
  97.  * One of the following will be defined automatically for you to select
  98.  * which memory model is in effect:
  99.  *
  100.  *        REALMODE    - 16 bit real mode (large memory model)
  101.  *        PM286        - 16 protected mode (large memory model)
  102.  *        PM386        - 32 protected mode (flat memory model)
  103.  */
  104.  
  105. #if defined(TNT) || defined(DOSX) || defined(X32VM) || defined(DPMI32)        \
  106.     || defined(DOS4GW) || defined(DJGPP) || defined(__WINDOWS32__)            \
  107.     || defined(__MSDOS32__)
  108. #define    PM386
  109. #elif defined(DPMI16) || defined(__WINDOWS16__)
  110. #define    PM286
  111. #else
  112. #define    REALMODE
  113. #endif
  114.  
  115. #pragma pack(1)
  116.  
  117. /* Provide definitions for the real mode register structures passed to
  118.  * the PM_int86() and PM_int86x() routines.
  119.  */
  120.  
  121. #if defined(REALMODE) || defined(PM286)
  122. #include <dos.h>
  123. typedef union REGS RMREGS;
  124. typedef struct SREGS RMSREGS;
  125. #else
  126. struct _RMWORDREGS {
  127.     ushort ax, bx, cx, dx, si, di, cflag, pad1;
  128.     };
  129.  
  130. struct _RMBYTEREGS {
  131.     uchar   al, ah, bl, bh, cl, ch, dl, dh;
  132.     };
  133.  
  134. typedef union {
  135.     struct  _RMWORDREGS x;
  136.     struct  _RMBYTEREGS h;
  137.     } RMREGS;
  138.  
  139. typedef struct {
  140.     ushort  es;
  141.     ushort  cs;
  142.     ushort  ss;
  143.     ushort    ds;
  144.     } RMSREGS;
  145. #endif
  146.  
  147. struct _PMDWORDREGS {
  148.     ulong    eax,ebx,ecx,edx,esi,edi,cflag;
  149.     };
  150.  
  151. struct _PMWORDREGS {
  152.     ushort     ax,ax_hi;
  153.     ushort     bx,bx_hi;
  154.     ushort     cx,cx_hi;
  155.     ushort     dx,dx_hi;
  156.     ushort     si,si_hi;
  157.     ushort     di,di_hi;
  158.     ushort    cflag,cflag_hi;
  159.     };
  160.  
  161. struct _PMBYTEREGS {
  162.     uchar    al, ah;    ushort:16;
  163.     uchar    bl, bh;    ushort:16;
  164.     uchar    cl, ch; ushort:16;
  165.     uchar    dl, dh; ushort:16;
  166.     };
  167.  
  168. typedef union {
  169.     struct  _PMDWORDREGS e;
  170.     struct  _PMWORDREGS  x;
  171.     struct  _PMBYTEREGS  h;
  172.     } PMREGS;
  173.  
  174. typedef struct {
  175.     ushort  es;
  176.     ushort  cs;
  177.     ushort  ss;
  178.     ushort    ds;
  179.     ushort    fs;
  180.     ushort    gs;
  181.     } PMSREGS;
  182.  
  183. /* Define a macro for creating physical base addresses from segment:offset */
  184.  
  185. #define MK_PHYS(s,o)  (((ulong)(s) << 4) + (ulong)(o))
  186.  
  187. /* Define the different types of modes supported. This is a global variable
  188.  * that can be used to determine the type at runtime which will contain
  189.  * one of these values.
  190.  */
  191.  
  192. typedef enum {
  193.     PM_realMode,
  194.     PM_286,
  195.     PM_386,
  196.     } PM_mode_enum;
  197.  
  198. /* Define a macro for changing the default stack size. For some compilers
  199.  * and extenders this is done at link time, for others you need to change
  200.  * a global variable (Borland C++, X-32 with any compiler). For compilers
  201.  * that do it on the command line, this expands to empty.
  202.  */
  203.  
  204. #ifdef    __WINDOWS__
  205. #define    DECLARE_STACK(s16,s32)
  206. #elif    defined(__TURBOC__)
  207. #define    DECLARE_STACK(s16,s32)    \
  208. extern uint _stklen = s16;
  209. #elif    defined(X32VM)
  210. #define    DECLARE_STACK(s16,s32)    \
  211. uint int _x32_stack_size = s32;
  212. #else
  213. #define DECLARE_STACK(s16,s32)
  214. #endif
  215.  
  216. #if        defined(__WINDOWS32__)
  217. #define    PMAPI    _DLLASM            /* 'C' calling conventions for Win32    */
  218. #elif    defined(__WINDOWS16__)
  219. #define    PMAPI    _DLLAPI            /* Pascal calling conventions for Win16    */
  220. #else
  221. #define PMAPI   _ASMAPI            /* 'C' calling conventions otherwise    */
  222. #endif
  223.  
  224. /*--------------------------- Function Prototypes -------------------------*/
  225.  
  226. #ifdef    __cplusplus
  227. extern "C" {            /* Use "C" linkage when in C++ mode    */
  228. #endif
  229.  
  230. /* Routine to return either PM_realMode, PM_286 or PM_386 */
  231.  
  232. int     PMAPI PM_getModeType(void);
  233.  
  234. /* Routines to access data through a selector and offset. For real mode
  235.  * and 16 bit protected mode (and also Win32), the offset can only be a
  236.  * maximum of 64k.
  237.  */
  238.  
  239. uchar     PMAPI PM_getByte(uint s, uint o);
  240. ushort     PMAPI PM_getWord(uint s, uint o);
  241. ulong     PMAPI PM_getLong(uint s, uint o);
  242. void     PMAPI PM_setByte(uint s, uint o, uchar v);
  243. void     PMAPI PM_setWord(uint s, uint o, ushort v);
  244. void     PMAPI PM_setLong(uint s, uint o, ulong v);
  245.  
  246. /* Routines for copying data between the applications data space and
  247.  * memory accessible through a selector and offset.
  248.  */
  249.  
  250. void     PMAPI PM_memcpynf(void *dst,uint src_s,uint src_o,uint n);
  251. void     PMAPI PM_memcpyfn(uint dst_s,uint dst_o,void *src,uint n);
  252.  
  253. /* Routine to return a selector to the BIOS data area at segment 0x40 */
  254.  
  255. uint     PMAPI PM_getBIOSSelector(void);
  256.  
  257. /* Routine to return a selector to the VGA frame buffer. The selector
  258.  * will map to the correct portion of video memory depending on the
  259.  * current video mode (0x3, 0x7 or graphics).
  260.  */
  261.  
  262. uint     PMAPI PM_getVGASelector(void);
  263.  
  264. /* Routines to return specific selectors to the VGA frame buffer memory */
  265.  
  266. uint     PMAPI PM_getVGAColorTextSelector(void);
  267. uint     PMAPI PM_getVGAMonoTextSelector(void);
  268. uint     PMAPI PM_getVGAGraphSelector(void);
  269.  
  270. /* Routines to map/free physical memory into the current DS segment. After
  271.  * the mapping has been allocated, it cannot be freed. Hence you should
  272.  * only allocate the mapping once and cache the value for use by other
  273.  * parts of your application. If this cannot be done, this function will
  274.  * return a NULL pointer.
  275.  *
  276.  * This routine will also work for memory addresses below 1Mb, but the
  277.  * memory cannot cross the 1Mb boundary.
  278.  */
  279.  
  280. void *     PMAPI PM_mapPhysicalAddr(ulong base,ulong limit);
  281.  
  282. /* Routine to load save default data segment selector value into a code
  283.  * segment variable, and another to load the value into the DS register.
  284.  */
  285.  
  286. void     PMAPI PM_loadDS(void);
  287. void     PMAPI PM_saveDS(void);
  288.  
  289. /* Routine to get a selector:offset for accessing a low 1Mb memory block.
  290.  * You dont need to free this pointer, but in 16 bit protected mode
  291.  * the selector allocated will be re-used the next time this routine is
  292.  * called. If you need a permanent selector, allocate it with
  293.  * PM_createSelector instead.
  294.  */
  295.  
  296. void     PMAPI PM_mapRealPointer(uint *sel,uint *off,uint r_seg,uint r_off);
  297.  
  298. /* Routine to create an arbritray selector to physical memory. In 16 bit
  299.  * protected mode you can pass a 32 bit limit to create a 32 bit
  300.  * protected mode data selector.
  301.  */
  302.  
  303. uint     PMAPI PM_createSelector(ulong base,ulong limit);
  304. void     PMAPI PM_freeSelector(uint sel);
  305.  
  306. /* Routine to create 32 bit code segment alias selector from a data
  307.  * selector. This is only useful for 16 bit Windows code that
  308.  * needs to be able to call 32 bit protected mode code in a USE32 segment.
  309.  * The selector can be freed with PM_freeSelector();
  310.  */
  311.  
  312. #ifdef    __WINDOWS16__
  313. uint     PMAPI PM_createCode32Alias(uint sel);
  314. #endif
  315.  
  316. /* Routine to allocate a block of conventional memory below the 1Mb
  317.  * limit so that it can be accessed from real mode. Ensure that you free
  318.  * the segment when you are done with it.
  319.  *
  320.  * This routine returns a selector and offset to the segment that has been
  321.  * allocated, and also returns the real mode segment and offset which can
  322.  * be passed to real mode routines. Will return 0 if memory could not be
  323.  * allocated.
  324.  *
  325.  * Please note that with some DOS extenders, memory allocated with the
  326.  * following function cannot be freed, hence it will be allocated for the
  327.  * life of your program. Thus if you need to call a bunch of different
  328.  * real-mode routines in your program, allocate a single large buffer at
  329.  * program startup that can be re-used throughout the program execution.
  330.  */
  331.  
  332. int     PMAPI PM_allocRealSeg(uint size,uint *sel,uint *off,uint *r_seg,uint *r_off);
  333. void    PMAPI PM_freeRealSeg(uint sel,uint off);
  334.  
  335. /* Routine to call a real mode assembly language procedure. Register
  336.  * values are passed in and out in the 'regs' and 'sregs' structures. We
  337.  * do not provide any method of copying data from the protected mode stack
  338.  * to the real mode stack, so if you need to pass data to real mode, you will
  339.  * need to write a real mode assembly language hook to recieve the values
  340.  * in registers, and to pass the data through a real mode block allocated
  341.  * with the PM_allocRealSeg() routine.
  342.  */
  343.  
  344. void     PMAPI PM_callRealMode(uint seg,uint off, RMREGS *regs,RMSREGS *sregs);
  345.  
  346. /* Routines to generate real mode interrupts using the same interface that
  347.  * is used by int86() and int86x() in realmode. This routine is need to
  348.  * call certain BIOS and DOS functions that are not supported by some
  349.  * DOS extenders. No translation is done on any of the register values,
  350.  * so they must be correctly set up and translated by the calling program.
  351.  *
  352.  * Normally the DOS extenders will allow you to use the normal int86()
  353.  * function directly and will pass on unhandled calls to real mode to be
  354.  * handled by the real mode handler. However calls to int86x() with real
  355.  * mode segment values to be loaded will cause a GPF if used with the
  356.  * standard int86x(), so you should use these routines if you know you
  357.  * want to call a real mode handler.
  358.  */
  359.  
  360. int     PMAPI PM_int86(int intno, RMREGS *in, RMREGS *out);
  361. int     PMAPI PM_int86x(int intno, RMREGS *in, RMREGS *out,RMSREGS *sregs);
  362.  
  363. /* Routines to generate native interrupts (ie: protected mode interrupts
  364.  * for protected mode apps) using an interface the same as that use by
  365.  * int86() and int86x() in realmode. These routines are required because
  366.  * many 32 bit compilers use different register structures and different
  367.  * functions causing major portability headaches. Thus we provide our
  368.  * own and solve it all in one fell swoop, and we also get a routine to
  369.  * put stuff into 32 bit registers from real mode ;-)
  370.  */
  371.  
  372. void     PMAPI PM_segread(PMSREGS *sregs);
  373. int     PMAPI PM_int386(int intno, PMREGS *in, PMREGS *out);
  374. int     PMAPI PM_int386x(int intno, PMREGS *in, PMREGS *out,PMSREGS *sregs);
  375.  
  376. /* Functions to manage real mode interrupt vectors */
  377.  
  378. void     PMAPI _PM_getRMvect(int intno, long *realisr);
  379. void     PMAPI _PM_setRMvect(int intno, long realisr);
  380.  
  381. /* Function to return the amount of available physical and total memory.
  382.  * The results of this function are *only* valid before you have made any
  383.  * calls to malloc() and free(). If you need to keep track of exactly how
  384.  * much memory is currently allocated, you need to call this function to
  385.  * get the total amount of memory available and then keep track of
  386.  * the available memory every time you call malloc() and free().
  387.  */
  388.  
  389. void    PMAPI PM_availableMemory(ulong *physical,ulong *total);
  390.  
  391. #ifdef    __cplusplus
  392. }                        /* End of "C" linkage for C++    */
  393. #endif
  394.  
  395. #pragma pack()
  396.  
  397. #endif /* __PMODE_H */
  398.